// ml:run = $bin < bfdiff.in
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
struct node{
    int l, r, ind;
    long long x;
    node () {}
    node (int l, int r, int ind):l(l), r(r), ind(ind),  x(r-l+1LL) {}
}A[410], B[410];
struct point{
    int x, y;
    point () {}
    point (int x, int y):x(x), y(y) {}
    bool operator<(const point &a)const{
        if (x==a.x)
            return y<a.y;
        return x<a.x;
    }
}pt[300];
int R, c, n;
int vis[410], vis2[410];
long long area[300], a2[300];
int belong[410];
int ans;
int ca, cb, cc;
int div(int l){
    for (int i=l+1;i<n;i++)
        if (pt[i].x!=pt[i-1].x)
            return i;
    return n;
}
bool judge(int a, int b){
    if (A[a].l>A[b].r) return false;
    if (A[a].r<A[b].l) return false;
    return true;
}
void dfs(int x){
    vis[x]=1;
    if (x>=ca) belong[x]=cc;
    for (int i=0;i<ca+cb;i++)
        if (!vis[i] && (judge(x, i)|| A[i].ind==A[x].ind)){
            if (vis2[A[i].ind]==0){
                a2[cc]+=A[i].x;
                vis2[A[i].ind]=1;
            }
            dfs(i);
        }
}
void pr(int l, int r){
    for (int i=l;i<=r;i++) printf("%d %d %d %lld\n", A[i].l, A[i].r, A[i].ind, A[i].x);
}
int main()
{
    std::ios_base::sync_with_stdio(false);
    int t;
    scanf("%d", &t);
    for (int TT=1;TT<=t;TT++){
        ans=0;
        scanf("%d%d%d", &R, &c, &n);
        for (int i=0;i<n;i++)
            scanf("%d%d", &pt[i].x, &pt[i].y);
        sort(pt, pt+n);
        ca=0;
        int l=0, r=-1;
        int level=0;
        while(l<n){
            if (pt[l].x>level+1){
                long long sum=0;
                memset(vis2, 0, sizeof(vis2));
                for (int i=0;i<ca;i++)
                    if (vis2[A[i].ind]==0){
                        sum+=A[i].x;
                        vis2[A[i].ind]=1;
                    }
                ca=1;
                A[0]=node(1, c, 0);
                A[0].x=sum+1LL*c*(pt[l].x-1-level);
                level=pt[l].x-1;
            }
            cb=cc=0;
            r=div(l);
            int last=0;
            for (int i=l;i<r;i++){
                if (pt[i].y>last+1){
                    A[ca+cb]=node(last+1, pt[i].y-1, ca+cb);
                    cb++;
                }
                last=pt[i].y;
            }
            if (last<c){
                A[ca+cb]=node(last+1,c, ca+cb);
                cb++;
            }

            /* printf("------\n"); */
            /* printf("%d\n", pt[l].x); */
            /* pr(0, ca-1); */
            /* printf("------\n"); */
            /* pr(ca, ca+cb-1); */
            /* printf("-----\n"); */

            memset(a2, 0, sizeof(a2));
            memset(vis, 0, sizeof(vis));
            memset(vis2, 0, sizeof(vis2));
            for (int i=ca;i<ca+cb;i++)
                if (vis[i]==0){
                    a2[cc]+=A[i].x;
                    belong[i]=cc;
                    vis2[A[i].ind]=1;
                    dfs(i);
                    cc++;
                }
            for (int i=ca;i<ca+cb;i++) A[i].ind=belong[i];
            for (int i=0;i<ca;i++)
                if (vis[i]==0 && vis2[A[i].ind]==0){
                    area[ans++]=A[i].x;
                    vis2[A[i].ind]=1;
                }
            for (int i=0;i<cb;i++){
                A[i]=A[i+ca];
                A[i].x=a2[A[i].ind];
            }
            ca=cb;
            level=pt[l].x;
            l=r;
        }
        if (level<R){
            long long sum=0;
            memset(vis2, 0, sizeof(vis2));
            for (int i=0;i<ca;i++)
                if (vis2[A[i].ind]==0){
                    sum+=A[i].x;
                    vis2[A[i].ind]=1;
                }
            area[ans++]=sum+1LL*(R-level)*c;
            ca=0;
        }
        memset(vis2, 0, sizeof(vis2));
        for (int i=0;i<ca;i++)
            if (vis2[A[i].ind]==0){
                area[ans++]=A[i].x;
                vis2[A[i].ind]=1;
            }
        printf("Case #%d:\n", TT);
        printf("%d\n", ans);
        sort(area, area+ans);
        for (int i=0;i<ans;i++)
            printf("%lld%c", area[i], i==ans-1?'\n':' ');
    }
    return 0;
}

